package com.yuanqi.Utils;


import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtil {

    public static  String CreateJwt(Map<String,Object> clams,String Key,Long time) {
        Long Time = System.currentTimeMillis()+time;
        Date date = new Date(Time);
        JwtBuilder jwtBuilder = Jwts.builder()
                .setClaims(clams)
                .setExpiration(date)
                .signWith(SignatureAlgorithm.HS256, Key.getBytes());
        return jwtBuilder.compact();
    }


    public  static Claims parser(String token, String key) {
       Claims claims =  Jwts.parser()
                .setSigningKey(key.getBytes())
                .parseClaimsJws(token).getBody();
        return claims;
    }
}
